import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../views/login.vue')
  },
  {
    path: '/login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/layout',
    component: () => import('../views/layout.vue'),
    redirect: '/tool/toollist',
    children: [
      {
        path: '/tool/toollist',
        component: () => import('../views/Home.vue')
      },
      {
        path: '/target/tagetlist',
        component: () => import('../components/uploud/uploditem/uploud.vue')
      },
      {
        path: '/list',
        component: () => import('../components/uploud/list.vue')
      },
      {
        path: '/user/userlist',
        component: () => import('../components/user/userlist.vue')
      },
      {
        path: '/user/usermanage',
        component: () => import('../components/user/usermanage.vue')
      },
      {
        path: '/user/userlog',
        component: () => import('../components/user/userlog.vue')
      },
      {
        path: '/fofa/list',
        component: () => import('../components/uploud/list.vue')
      },
      {
        path: '/edit',
        component: () => import('../views/poents/edit.vue')
      },
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    const token = localStorage.getItem('token');
    if (token) {
      next('/login');
    } else {
      next();
    }
  } else {
    next();
  }
});

export default router
